<template>
<d2-container>
  <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"
           style="width: 30%;">
    <el-form-item label="名字" prop="fullName">
      <el-input v-model="ruleForm.fullName"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="total">
      <el-input type="total" v-model="ruleForm.address" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="负责人" prop="header">
      <el-input type="text" v-model="ruleForm.header"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="phone">
      <el-input type="text" v-model="ruleForm.phone"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="ruleForm.remark"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>

</d2-container>
</template>

<script>
const axios = require('axios');
import {request} from "@/network/request";

export default {
  name: 'create',
  data() {
    return {
      ruleForm: {
        fullName: '中粮集团有限公司',
        header: '吕军',
        phone: '13344556677',
        address: '北京市朝阳区朝阳门南大街8号',
        remark: '无'
      },
      rules: {
        fullName: [
          {required: true, message: '请输入公司名称', trigger: 'blur'}
        ],
        header: [
          {required: true, message: '请输入负责人姓名', trigger: 'blur'}
        ],
        phone: [
          {required: true, message: '请输入联系电话', trigger: 'blur'}
        ],
        address: [
          {required: true, message: '请输入地址', trigger: 'blur'}
        ],
        remark: [
          {required: true, message: '请输入备注', trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      let _this = this;
      request({
          url: 'supplier/add',
          method: 'post',
          params: {
            fullName: _this.ruleForm.fullName,
            header: _this.ruleForm.header,
            phone: _this.ruleForm.phone,
            address: _this.ruleForm.address,
            remark: _this.ruleForm.remark
          }
        }, res => {

          alert("添加成功！");
          console.log(res);
        }, err => {
          alert("添加失败，请重试！");
          console.log(err);
        }
      );
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>
